﻿#ifndef PRINTERCONTROL_H
#define PRINTERCONTROL_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>

class PrinterControl : public QObject
{
    Q_OBJECT

    // 连接状态
    Q_PROPERTY(bool linkState READ linkState WRITE setLinkState NOTIFY linkStateChanged FINAL)

    // 端口号
    Q_PROPERTY(QString PortName READ PortName WRITE setPortName NOTIFY PortNameChanged FINAL)
    // 波特率
    Q_PROPERTY(QString BaudRate READ BaudRate WRITE setBaudRate NOTIFY BaudRateChanged FINAL)
    // 数据位
    Q_PROPERTY(QString DataBite READ DataBite WRITE setDataBite NOTIFY DataBiteChanged FINAL)
    // 校验位
    Q_PROPERTY(QString Parity READ Parity WRITE setParity NOTIFY ParityChanged FINAL)
    // 停止位
    Q_PROPERTY(QString StopBite READ StopBite WRITE setStopBite NOTIFY StopBiteChanged FINAL)

public:
    PrinterControl(QObject *parent = nullptr);
    ~PrinterControl();

    // 打印机串口对象
    QSerialPort* printerSerial;

    // 打印机连接 参数设定
    void setConnectParameter(QString _portName, QString _baudRate,
                             QString _bataBite, QString _parity, QString _stopBite);

    // 连接到电脑
    void linkToComputer();

    // 打印动作 - 炜煌打印机
    void printerActive_WH(QString company, QString nameData, QString numberData,
                          QString knife, QString roller,
                          QString stress01, QString stress02, QString stress03,
                          QString fwdknife01, QString fwdknife02, QString fwdknife03,
                          QString backknife01, QString backknife02, QString backknife03);
    void printerActive_RG(QString company, QString nameData, QString numberData,
                          QString knife, QString roller,
                          QString stress01, QString stress02, QString stress03,
                          QString fwdknife01, QString fwdknife02, QString fwdknife03,
                          QString backknife01, QString backknife02, QString backknife03);



    bool linkState() const;
    void setLinkState(bool newLinkState);

    QString PortName() const;
    void setPortName(const QString &newPortName);

    QString BaudRate() const;
    void setBaudRate(const QString &newBaudRate);

    QString DataBite() const;
    void setDataBite(const QString &newDataBite);

    QString Parity() const;
    void setParity(const QString &newParity);

    QString StopBite() const;
    void setStopBite(const QString &newStopBite);

signals:
    void linkStateChanged();
    void PortNameChanged();

    void BaudRateChanged();

    void DataBiteChanged();

    void ParityChanged();

    void StopBiteChanged();



private:
    bool m_linkState;
    QString m_PortName;
    QString m_BaudRate;
    QString m_DataBite;
    QString m_Parity;
    QString m_StopBite;
};

#endif // PRINTERCONTROL_H
